package com.xrj.gateway.controller;

import com.mall.common.annotation.PassToken;
import com.mall.common.response.Response;
import com.mall.shopping.constant.ProductConstant;
import com.mall.shopping.constant.ShoppingServiceEnum;
import com.mall.shopping.dto.bo.resp.CategoriesResp;
import com.mall.shopping.dto.bo.resp.HomePageResp;
import com.mall.shopping.dto.bo.resp.NavigationResp;
import com.mall.shopping.service.TbItemService;
import com.mall.shopping.service.TbPanelService;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: xrj
 * @date: 2022/5/1 23:41
 * @description:
 */
@RestController
@RequestMapping("/shopping")
public class ShoppingController {

    @Reference(timeout = 3000,check = false)
    private TbItemService itemService;

    @Reference(timeout = 3000,check = false)
    private TbPanelService panelService;

    @ApiOperation(value = "轮播图信息",httpMethod = "GET")
    @GetMapping("/homepage")
    @PassToken
    public Object getHomepage(){
        HomePageResp resp = panelService.queryHomepageInfo();
        if (!ShoppingServiceEnum.SUCCESS.getCode().equals(resp.getCode())){
            return Response.operationFailed(resp.getMsg());
        }
        return Response.success(resp.getPanelModels(),"查询成功");
    }

    @ApiOperation(value = "导航栏信息",httpMethod = "GET")
    @GetMapping("/navigation")
    @PassToken
    public Object getNavigation(){
        NavigationResp resp = panelService.queryPanelContentWithRoot(ProductConstant.ROOT_CATEGORY);
        if (!ShoppingServiceEnum.SUCCESS.getCode().equals(resp.getCode())){
            return Response.operationFailed(resp.getMsg());
        }
        return Response.success(resp.getPanelContents(),"查询成功");
    }

    @ApiOperation(value = "商品分类信息",httpMethod = "GET")
    @GetMapping("/categories")
    @PassToken
    public Object getCategories(){
        CategoriesResp resp = itemService.queryItemCategory();
        if (!ShoppingServiceEnum.SUCCESS.getCode().equals(resp.getCode())){
            return Response.operationFailed(resp.getMsg());
        }
        return Response.success(resp.getProductCateModels(),"查询成功");
    }

    @ApiOperation(value = "商品推荐信息",httpMethod = "GET")
    @GetMapping("/recommend")
    @PassToken
    public Object getRecommend(){
        HomePageResp resp = panelService.queryRecommend();
        if (!ShoppingServiceEnum.SUCCESS.getCode().equals(resp.getCode())){
            return Response.operationFailed(resp.getMsg());
        }
        return Response.success(resp.getPanelModels(),"查询成功");
    }

}
